package summerbug.hanzi;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import java.util.List;

import summerbug.hanzi.model.HanZiTable;
import summerbug.hanzi.model.dao.DaoSession;
import summerbug.hanzi.model.dao.HanZiTableDao;

/**
 * Created by 76336 on 2018/5/13.
 */

public class Receiver extends BroadcastReceiver {
    private MyApplication myApplication;
    private ZiDianActivity ziDianActivity;

    public Receiver(MyApplication myApplication,ZiDianActivity ziDianActivity){
        this.myApplication = myApplication;
        this.ziDianActivity = ziDianActivity;
    }
    @Override
    public void onReceive(Context context, Intent intent) {
        switch (intent.getAction()){
            case "ACTION_REFRESH_UI":
                DaoSession session = myApplication.getDaoSession();

                HanZiTableDao hanZiTableDao = session.getHanZiTableDao();
                List<HanZiTable> hanZiTables = hanZiTableDao.queryBuilder().build().list();

                ziDianActivity.loadData(hanZiTables);
                break;
        }
    }
}
